import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
file_path = r'男子体能测试成绩.xlsx'
data = pd.read_excel(file_path)
min_value = np.floor(data['1000米（分）'].min())  # 向下取整，结果为3.0
max_value = np.ceil(data['1000米（分）'].max())  # 向上取整，结果为6.0
bin_edges = np.arange(min_value, max_value + 0.2, 0.2)
plt.figure(figsize=(8, 6))
plt.hist(data['1000米（分）'], bins=bin_edges, color='#008B8B', edgecolor='black')
plt.title('男子1000米项目用时分布直方图', fontsize=16)
plt.xlabel('1000米项目用时（分）', fontsize=14)
plt.ylabel('频数', fontsize=14)
plt.xticks(ticks=bin_edges)
plt.rcParams['font.sans-serif'] = 'SimHei'
plt.style.use('bmh')
plt.show()